<?php
require_once "metadata/Continent.class.php";
class ContinentModel
{
    var $db;

    function __construct($db_link)
    {
        $this->db = $db_link;
    }

    function getAllContinents()
    {
        $query = "SELECT * FROM continents" or die("Error in the consult.." . mysqli_error($this->db));

        //execute the query.
        $result = $this->db->query($query);

        $continents = array();

        while($row = mysqli_fetch_array($result))
        {
            $continent = new Continent($row["id"], $row["name"]);
            $continents[count($continents)] = $continent;
        }
        return $continents;
    }

    function getContinent($id)
    {
        $query = "SELECT * FROM continents WHERE id = '$id'" or die("Error in the consult.." . mysqli_error($this->db));

        //execute the query.
        $result = $this->db->query($query);

        while($row = mysqli_fetch_array($result))
        {
            return new Continent($row["id"], $row["name"]);
        }
    }

}
?>